const app1 = new Vue({
    el: '#app1',
    data: {
        a: [],
        username: 'Candy',
        author: 'author',
        show_header: true,
        is_login: false,
        article_title: '',
        cate_value: '',
        options: [{
          value: 'python',
          label: 'Python'
        }, {
          value: 'java',
          label: 'Java'
        }, {
          value: 'php',
          label: 'PHP'
        }, {
          value: 'javascript',
          label: 'JavaScript'
        }, {
          value: 'linux',
          label: 'Linux'
        },{
          value: 'other',
          label: 'Other'
        }]
    },
    created(){
        console.log("初始化")
        this.loading = true
    },
    methods:{
        update(){
//            console.log(1111)
            // 清空上次的元素
            <!-- 失去效果-->
            var token = localStorage.getItem('token');
            console.log(token);
            document.getElementById("btn").disabled=true;
            <!--变成灰色-->
            document.getElementById('btn').style.color = "SlateGray";
            document.getElementById('btn').value = "上传中..."
            var content = document.getElementById('content_area').innerHTML;
            $.ajax({
                url:"/article/upload",//请求的url地址
                dataType:"json",//返回格式为json
                async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                headers: {
                    "Accept": "application/json; charset=utf-8",
                    "token": token
                },
                data:{"cate_value":this.cate_value, "article_title":this.article_title,"content": content},//参数值
                type:"POST",//请求方式
                beforeSend:function(){
                    //请求前的处理
                },
                success:function(req){
                    //请求成功时处理
                    // 返回状态码
                    var code = req.code
                    if (code != 200){
                        alert(req.results.message)
                        <!-- 失去效果-->
                        document.getElementById("btn").disabled=false;
                        <!--变成灰色-->
                        document.getElementById('btn').style.color = "White";
                        document.getElementById('btn').value = "写好啦"
                        return
                    };
                    var res = req.results;
                    // JSON -> STRING
                    alert(req.status)
                    <!-- 失去效果-->
                    document.getElementById("btn").disabled=false;
                    <!--变成灰色-->
                    document.getElementById('btn').style.color = "White";
                    document.getElementById('btn').value = "写好啦"
                    location.href = '/'
                },
                complete:function(){
                    //请求完成的处理
                },
                error:function(error){
                    //请求出错处理
                    alert(error);
                    <!-- 失去效果-->
                    document.getElementById("btn").disabled=false;
                    <!--变成灰色-->
                    document.getElementById('btn').style.color = "White";
                    document.getElementById('btn').value = "写好啦"
                }
            });
        },
        return_ref(){
            location.href = '/static/templates/index.html'
        },
    }
});

function shuffleSelf(array, size) {
    var index = -1,
        length = array.length,
        lastIndex = length - 1;

    size = size === undefined ? length : size;
    while (++index < size) {
        // var rand = baseRandom(index, lastIndex),
        var rand = index + Math.floor( Math.random() * (lastIndex - index + 1))
            value = array[rand];

        array[rand] = array[index];

        array[index] = value;
    }
    array.length = size;
    return array;
}
